<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>GX College Social Networking</title>
</head>

<body>
<table width="891" height="649" border="0">
  <tr>
    <td  bgcolor="#6699FF" height="34" colspan="8"><marquee>GX College Networking</marquee></td>
  </tr>
  <tr>
    <td  bgcolor="#6699FF" width="139" height="43"><a href="/AdministratorHomePage.php">Homepage</a></td>
    <td  bgcolor="#6699FF" width="139"><a href="/AdministratorHomePageProfile.php">Profile</a></td>
    <td  bgcolor="#6699FF" width="106"><a href="/AdministratorHomePageStudent.php"> Student</a></td>
    <td  bgcolor="#6699FF" width="129"><a href="/AdministratorHomePageProfessor.php"> Professor</a></td>
    <td  bgcolor="#6699FF" width="61"><a href="/logout.php">Logout</a></td>
    <td bgcolor="#6699FF" width="194">
    <form action="/ViewAllCandidateSearchAdministrator.php" method="post">
Enter Candidate's first name:  
<input type="text"  name="firstname" />
<input type="submit" name="submit" value="submit" />
</form>
    </td>
  </tr>
  <tr>
    <td  bgcolor="#6699FF" height="281" rowspan="2"><table  bgcolor="#6699FF" width="200" border="0">
      <tr>
        <td><a href="/ViewProfileAdministrator.php">View Profile</a></td>
      </tr>
      <tr>
        <td><a href="/EditProfileAdministrator.php"> Edit Profile</a></td>
      </tr>
      <tr>
        <td><a href="/ChangePasswordAdministrator.php">Change Password</a></td>
      </tr>
    </table>* Editable Entries</td>
    <td colspan="7">
	<?php 
session_start(); 
$cuid = $_SESSION['username'];

$conn = oci_connect("gaurav", "gaurav", "xe"); 

  $query =
    "SELECT *
     FROM   Candidate
     WHERE  Cuid = :cuid";

  $conn = oci_connect("gaurav", "gaurav", "xe"); 
  $bindargs = array();
  array_push($bindargs, array('CUID', $cuid, -1));

     $pointer = db_do_query($conn, $query, OCI_FETCHSTATEMENT_BY_ROW,$bindargs);
 //  $pointer = db_do_query($conn, $query, OCI_FETCHSTATEMENT_BY_ROW); 


  ui_print_modify_candidate($pointer[0], $_SERVER['SCRIPT_NAME']);
  
  // Execute query and display results 
/*function db_do_query($conn, $statement)
{
  $stid = oci_parse($conn, $statement);
  if (!$stid) {
    db_error($conn, __FILE__, __LINE__);
  }

  $r = oci_execute($stid, OCI_DEFAULT);
  if (!$r) {
    db_error($stid, __FILE__, __LINE__);
  }
 $r = oci_fetch_all($stid, $results, null, null,
                     OCI_FETCHSTATEMENT_BY_ROW);
  return($results);
}*/

function db_do_query($conn, $statement, $resulttype, $bindvars = array())
{
$stid = oci_parse($conn, $statement);
  if (!$stid) {
    db_error($conn, __FILE__, __LINE__);
  }

  // Bind the PHP values to query bind parameters
  foreach ($bindvars as $b) {
    // create local variable with caller specified bind value
    $$b[0] = $b[1];  
    // oci_bind_by_name(resource, bv_name, php_variable, length)
    $r = oci_bind_by_name($stid, ":$b[0]", $$b[0], $b[2]); 
    if (!$r) {
      db_error($stid, __FILE__, __LINE__);
    }
  }
  $r = oci_execute($stid, OCI_DEFAULT);
  if (!$r) {
        db_error($stid, __FILE__, __LINE__);
  }
  $r = oci_fetch_all($stid, $results, null, null, $resulttype);
  return($results);
}

function db_error($r = false, $file, $line)
{
  $err =  $r ? oci_error($r) : oci_error();

  if (isset($err['message'])) {
    $m = htmlentities($err['message']);
  }
  else {  
    $m = 'Unknown DB error';
  }

  echo '<p><b>Error</b>: at line '.$line.' of '.$file.'</p>';
  echo '<pre>'.$m.'</pre>';

  exit;
}

function ui_print_modify_candidate($empdetails, $posturl)
{
  if (!$empdetails) {
    echo '<p>No Candidate record selected</p>';
  }
  else {
    $cuid = htmlentities($empdetails['CUID']);
    $firstname = htmlentities($empdetails['FNAME']);
    $middlename = htmlentities($empdetails['MNAME']);
    $lastname = htmlentities($empdetails['LNAME']);
    $address1 = htmlentities($empdetails['ADDRESS1']);
    $address2 = htmlentities($empdetails['ADDRESS2']);
	$city = htmlentities($empdetails['CITY']);
    $state = htmlentities($empdetails['STATE']);
    $country = htmlentities($empdetails['COUNTRY']);
    $zipcode = htmlentities($empdetails['ZIPCODE']);
    $cellnumber = htmlentities($empdetails['CELLNUMBER']);
    $sex = htmlentities($empdetails['SEX']);
	$departmentid = htmlentities($empdetails['DEPTID']);

    echo <<<END
  <form method="post" action="/CheckEditAdministrator.php">
  <table size="1000">
    <tr>
      <td bgcolor="#6699FF">Candidate ID</td>
      <td bgcolor="#6699FF">$cuid</td></tr>
    <tr>
      <td bgcolor="#6699FF">First Name</td>
      <td bgcolor="#6699FF"><input type="" readonly name="firstname" value="$firstname" size="15"></td>
    </tr>
    <tr>
      <td bgcolor="#6699FF">Middle Name</td>
      <td bgcolor="#6699FF"><input type="text" readonly name="middlename" value="$middlename" size="15"></td>
    </tr>
    <tr>
      <td bgcolor="#6699FF">Last Name</td>
      <td bgcolor="#6699FF"><input type="text" readonly name="lastname" value="$lastname" size="15"></td>
    </tr>
    <tr>
      <td bgcolor="#6699FF">Address 1*</td>
      <td bgcolor="#6699FF"><input type="text" name="address1" value="$address1" size="40"></td>
    </tr>
	 <tr>
      <td bgcolor="#6699FF">Address 2*</td>
      <td bgcolor="#6699FF"><input type="text" name="address2" value="$address2" size="40"></td>
    </tr>
	<tr>
      <td bgcolor="#6699FF">City*</td>
      <td bgcolor="#6699FF"><input type="text" name="city" value="$city" size="15"></td>
    </tr>
	<tr>
      <td bgcolor="#6699FF">State*</td>
      <td bgcolor="#6699FF"><input type="text" name="state" value="$state" size="15"></td>
    </tr>
	<tr>
      <td bgcolor="#6699FF">Country*</td>
      <td bgcolor="#6699FF"><input type="text" name="country" value="$country" size="15"></td>
    </tr>
	<tr>
      <td bgcolor="#6699FF">ZipCode*</td>
      <td bgcolor="#6699FF"><input type="text" name="zipcode" value="$zipcode" size="15"></td>
    </tr>
	<tr>
      <td bgcolor="#6699FF">Cell Number*</td>
      <td bgcolor="#6699FF"><input type="text" name="cellnumber" value="$cellnumber" size="15"></td>
    </tr>
	<tr>
      <td bgcolor="#6699FF">Sex</td>
      <td bgcolor="#6699FF"><input type="text" readonly name="sex" value="$sex" size="15"></td>
    </tr>
	<tr>
      <td bgcolor="#6699FF">Department ID</td>
      <td bgcolor="#6699FF"><input type="text" readonly name="departmentid" value="$departmentid" size="15"></td>
    </tr>
  </table>
      <input type="submit" value="Submit" name="savemodifiedemp">
  <input type="reset" value="Cancel" name="cancel">
  </form>
END;
  }
} ?></td>
  </tr>
</table>
<p>&nbsp;</p>
</body>
</html>